import Block from "./Block"
import GridSystem from "../GridSystem"
import { ControlPoint, BlockType } from "../Constants";

class MyTriangle extends Block {

    fill: string;
    constructor(x: number = 40, y: number = 40, width: number = 100, height: number = 100, fill: string = "black") {
        super(x, y, width, height);
        this.fill = fill;
        this.class = BlockType.TRIANGLE;
    }

    draw(x: number = 40, y: number = 40, width: number = 100, height: number = 100) {
        let ctx = GridSystem.gls.ctx;
        ctx.save()
        let { x: x1, y: y1 } = this.setAdsorption(x, y, width, height)
        x = x1;
        y = y1;
        this.setAngle(x, y, width, height,)
        this.setSizeInfo(x, y, width, height)
        // ------ 公共部分

        ctx.beginPath();
        ctx.moveTo(x + width / 2, y);
        ctx.lineTo(x + width, y + height);
        ctx.lineTo(x, y + height);
        ctx.closePath(); //闭合
        ctx.fillStyle = "green"; //先选择颜色
        ctx.fill();	//再填充
        ctx.restore()
        this.setFocusStyle();
        this.setControlPoints(x, y, width, height);
        this.isDraged = false;
        this.drawLink(x, y, width, height);
        this.update(x, y, width, height)
    }
}

export default MyTriangle;